import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from "@dfeidao/atom-web/msg/nodejs";
import whoami from '@dfeidao/atom-web/msg/whoami';
import confirm, { ConfirmResult } from '@dfeidao/atom-web/msgbox/confirm';
import s_get from '@dfeidao/atom-web/storage/get';
import a015 from './a015';

// import whoami from '@dfeidao/atom-web/msg/whoami';
// import { send_msg as url, get_user_info } from './config';

import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';

export default async function a004(fd: IFeidaoAiBrowserComponent) {

	// 删除
	const input = fd.data.node.querySelectorAll('[data-feidao-name="list_checkbox"]:checked');
	// console.log("====" + input.length);
	if (input.length === 0) {
		error('请选择要删除数据');
		// fire('zjc-000001', 'ec-001', 'fail', '请选择要删除数据');
		return;
	} else {
		const ids: string[] = [];
		Array.from(input).forEach((ipt: HTMLInputElement) => {
			const id = ipt.getAttribute('data-feidao-id');
			ids.push(id);
		});
		const usercode: string[] = [];
		Array.from(input).forEach((ipt: HTMLInputElement) => {
			// const ucode = ipt.getAttribute('data-feidao-id');
			const ucode = ipt.getAttribute('data-feidao-usercode');
			usercode.push(ucode);
		});
		// console.log(usercode);
		// const user = await whoami(get_user_info);
		// console.log(user)
		const prid = await s_get('productid');
		const user = await whoami();
		const query = {
			productid: prid,
			ids,
			usercode,
			username: user.user_name
		};

		const flag = await confirm('您确定要删除此用户吗？', '提示', '是', '否');
		switch (flag) {
			case ConfirmResult.YES:
				// console.log(productid);
				// console.log(resource_no);
				const del_res = await nodejs('consumer/zj-000001/s002', query);
				if (del_res === 'success') {

					fire('zj-000001', 'ec-003');
					success('删除成功');
					// fire('zjc-000001', 'ec-001', 'success', '删除成功');
					await a015(fd);

				} else {
					error('删除失败');
					// fire('zjc-000001', 'ec-001', 'fail', '删除失败');
				}
				break;
			case 'no':
				// 点击否要做的操作
				// todo
				break;
			default:
				// cancel
				// todo
				break;
		}


	}
}
